using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;


namespace TankWars
{
    public class GameField
    {
        //Used to draw blocks.
        private SpriteBatch spriteBatch;

        //Temporary picture for a block.
        private Texture2D blockTexture;

        //Matrix that contains which spaces are collidable.
        public bool[,] field;

        //Size of the collidable blocks.
        public int blockSize = 15;

        //Width in blocks of the entire field.
        private int width = 69;

        //Height in block of the entire field.
        private int height = 52;

        public GameField(Texture2D blockTexture,SpriteBatch spriteBatch)
        {
            //Initialize the spritebatch
            this.spriteBatch = spriteBatch;

            //Initialize the block texture.
            this.blockTexture = blockTexture;

            field = new bool[width,height];
            for (int x = 0; x < width; x++)
            for (int y = 0; y < height; y++)
                field[x, y] = false;

            for (int x = 20; x < 30; x++)
            for (int y = 12; y < 18; y++)
                field[x, y] = true;

            field[5, 5] = true;
            field[5, 8] = true;
            field[5, 29] = true;
            field[8, 27] = true;
            field[44, 5] = true;
            field[42, 7] = true;
            field[44, 29] = true;
            field[41, 29] = true;
        }

        //Does the given x,y location contain a block?
        public bool occupied(int x,int y)
        {
            //Out of bounds returns true to block
            //tanks from driving off the board.
            if ((x<0)||(x>=width))
              return false;
            if ((y<0)||(y>=height))
              return false;

            return field[x,y];
        }

        public void drawField(Map map)
        {
            this.spriteBatch.Begin();
            
            //Check the matrix for collidable locations.
            for (int x = 0; x < width; x++)
            for (int y = 0; y < height; y++)
            {
                //Draw a block if the position is true.
                if (field[x, y] == true)
                {
                    spriteBatch.Draw(blockTexture, map.GetTrueScreenPosition(new Vector2(x*blockSize,y*blockSize)), Color.White);
                }
            }
            this.spriteBatch.End();
        }

}
}
